package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.api.admin.ChannelControllerApi;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Title: TODO
 * @Description: TODO
 * @author: 丁丁
 * @date: 2021/3/8
 * @version:
 */
@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController implements ChannelControllerApi {
    @Autowired
    private AdChannelService channelService;

    /**
     * 分页查询
     * @param dto 分页查询参数
     * @return 分页查询结果
     */
    @Override
    @PostMapping("/list")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return channelService.findByNameAndPage(dto);
    }

    /**
     * 新增频道
     * @param channel
     * @return
     */
    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody AdChannel channel) {
        return channelService.insert(channel);
    }

    /**
     * 修改频道
     * @param channel
     * @return
     */
    @Override
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel channel) {
        return channelService.update(channel);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @Override
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return channelService.deleteById(id);
    }

    /**
     * 查询所有频道
     *
     * @return
     */
    @Override
    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }
}
